package com.example.homework2.deom;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/homework2/sendError")
public class sendErrorDemo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");

        PrintWriter writer = null;
        try {
            writer = resp.getWriter();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"Are you ready for it......?");
        } catch (IOException e) {
            writer.println(e.getMessage());
        }
        writer.println("当前页面正在响应一个错误");
    }
}
